unit Class_WGFL_X7;

interface
uses
  Classes,SysUtils,FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
  FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSSQL,
  FireDAC.Phys.MSSQLDef, Data.DB, FireDAC.Comp.Client, FireDAC.Stan.Param,
  FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet,
  FireDAC.VCLUI.Wait, FireDAC.Comp.UI,Rtti;

type
  KzFieldAttribute = class(TCustomAttribute)
  private
    FFieldName:string;
    FFieldType:string;
  public
    constructor Create(const AFieldName,AFieldType: string);overload;
  published
    property FieldName :string  read FFieldName write FFieldName;
    property FieldType :string  read FFieldType write FFieldType;
  end;

  TWGFLX7=class(TObject)
  private
    [KzField('UNIT_LINK','S')]
    FUNITLINK : string;
    [KzField('GZJG_IDEX','D')]
    FGZJGIDEX : Integer;
    [KzField('WAGE_KJND','D')]
    FWAGEKJND : Integer;
    [KzField('WAGE_KJQJ','D')]
    FWAGEKJQJ : Integer;
    [KzField('WAGE_IDEX','D')]
    FWAGEIDEX : Integer;
    [KzField('STAF_IDEX','D')]
    FSTAFIDEX : Integer;
    [KzField('STAF_BDID','D')]
    FSTAFBDID : Integer;
    [KzField('STAF_TYPE','D')]
    FSTAFTYPE : Integer;
    [KzField('STAF_BANK','S')]
    FSTAFBANK : string;
    [KzField('STAF_NUMB','S')]
    FSTAFNUMB : string;
    [KzField('WAGE_GSND','D')]
    FWAGEGSND : Integer;
    [KzField('WAGE_GSQJ','D')]
    FWAGEGSQJ : Integer;
    [KzField('GSND_GSQJ','D')]
    FGSNDGSQJ : Integer;
    [KzField('KJND_KJQJ','D')]
    FKJNDKJQJ : Integer;
    [KzField('HOLD_TYPE','D')]
    FHOLDTYPE : Integer;
    [KzField('IS_DEALED','D')]
    FISDEALED : Integer;
    [KzField('HOLD_FROM','D')]
    FHOLDFROM : Integer;
    [KzField('IS_HOLDED','D')]
    FISHOLDED : Integer;
  public
    FListData : TStringList;
  public
    function GetObjtIdentity:string;
  public
    destructor  Destroy; override;
    constructor Create;
  published
    property UNITLINK : string read FUNITLINK  write FUNITLINK;
    property GZJGIDEX : Integer read FGZJGIDEX  write FGZJGIDEX;
    property WAGEKJND : Integer read FWAGEKJND  write FWAGEKJND;
    property WAGEKJQJ : Integer read FWAGEKJQJ  write FWAGEKJQJ;
    property WAGEIDEX : Integer read FWAGEIDEX  write FWAGEIDEX;
    property STAFIDEX : Integer read FSTAFIDEX  write FSTAFIDEX;
    property STAFBDID : Integer read FSTAFBDID  write FSTAFBDID;
    property STAFTYPE : Integer read FSTAFTYPE  write FSTAFTYPE;
    property STAFBANK : string read FSTAFBANK  write FSTAFBANK;
    property STAFNUMB : string read FSTAFNUMB  write FSTAFNUMB;
    property WAGEGSND : Integer read FWAGEGSND  write FWAGEGSND;
    property WAGEGSQJ : Integer read FWAGEGSQJ  write FWAGEGSQJ;
    property GSNDGSQJ : Integer read FGSNDGSQJ  write FGSNDGSQJ;
    property KJNDKJQJ : Integer read FKJNDKJQJ  write FKJNDKJQJ;
    property HOLDTYPE : Integer read FHOLDTYPE  write FHOLDTYPE;
    property ISDEALED : Integer read FISDEALED  write FISDEALED;
    property HOLDFROM : Integer read FHOLDFROM  write FHOLDFROM;
    property ISHOLDED : Integer read FISHOLDED  write FISHOLDED;
  public
    class function  ReadDS(AUniQuery:TFDQuery):TWGFLX7;
  end;

implementation

uses
  Vcl.Dialogs,class_kzdebug;

{ TWGFLX7 }

constructor TWGFLX7.Create;
begin

end;

destructor TWGFLX7.Destroy;
begin

  inherited;
end;

function TWGFLX7.GetObjtIdentity: string;
begin
  Result:=Format('%S-%D-%D-%D-%D-%D',[FUNITLINK,FGZJGIDEX,FWAGEKJND,FWAGEKJQJ,FWAGEIDEX,FSTAFIDEX]);
end;

class function TWGFLX7.ReadDS(AUniQuery:TFDQuery):TWGFLX7;
var
  I:Integer;
  Field:TField;

  R: TRttiContext;
  T: TRttiType;
  F: TRttiField;
  C: TCustomAttribute;

  FS: TArray<TRttiField>;
begin
  Result:=TWGFLX7.Create;

  R:=TRttiContext.Create;
  T:=R.GetType(Result.ClassInfo);
  FS:=T.GetFields;

  with TWGFLX7(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields[I];
      for F in T.GetFields do
      begin
        for C in F.GetAttributes do
        begin
          if C is KzFieldAttribute then
          begin
            if KzFieldAttribute(C).FieldName=Field.FieldName then
            begin
              case F.FieldType.TypeKind of
                tkInteger:F.SetValue(Result,Field.AsInteger);
                tkString :F.SetValue(Result,Field.AsString);
                tkUString:F.SetValue(Result,Field.AsString);
              end;
            end;
          end;
        end;
      end;
    end;
  end;
end;

{ FieldAttribute }

constructor KzFieldAttribute.Create(const AFieldName,AFieldType: string);
begin
  FieldName:=AFieldName;
  FieldType:=AFieldType;
end;

end.

